<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;

        }

        .box {
            width: 1200px;
            height: 500px;
            margin: 0 auto;
            position: relative;
            overflow: hidden;
        }

        .wid {
            width: 6100px;
            height: 500px;
        }

        img {
            width: 1200px;
            height: 500px;
            position: relative;
            top: 0;
            left: 0;
        }

        .prev {
            position: absolute;
            left: 354px;
            top: 20%;
            display: inline-block;
            font-size: 40px;
            cursor: pointer;
        }

        .next {
            position: absolute;
            left: 1535px;
            top: 20%;
            display: inline-block;
            font-size: 40px;
            cursor: pointer;
        }
        .dis{
            width: 200px;
            height: 100px;
            position: absolute;
            top: 400px;
            left: 850px;
        }
        .dis>span{
            font-size: 60px;
            margin-left: 10px;
        }
        .bg{
            color: white;
        }
    </style>
</head>

<body>
    <div>
        <div class="box">
            <div class="wid">
                <img src="./img/4.jpg" alt="">
                <img src="./img/5.jpg" alt="">
                <img src="./img/6.jpg" alt="">
                <img src="./img/小海星.webp" alt="">
                <img src="./img/蓝天.jpg" alt="">
            </div>
        </div>
        <div>
            <span class="prev"> &lt; </span>
            <span class="next"> > </span>
        </div>
        <div class="dis">
            <span class="bg">.</span>
            <span>.</span>
            <span>.</span>
            <span>.</span>
            <span>.</span>
        </div>

    </div>
    
    <script>
        let currentIndex = 0;
        let imgHeight = 1205;
        let length = $('img').length;
        function showPic() {
            currentIndex = currentIndex >= length - 1 ? 0 : ++currentIndex;
            let distance = -currentIndex * imgHeight + 'px'
            $('img').animate({ 'left': distance }, 500)
            $('.dis>span').eq(currentIndex).addClass('bg').siblings().removeClass('bg')
            console.log('a');
        }
        let show
        function fun() {
            show = setInterval(showPic, 1000)
        }
        fun()


        // 上一张
        $('.prev').click(function () {
            clearInterval(show)
            currentIndex = currentIndex <= 0 ? length - 1 : --currentIndex
            let distance = -currentIndex * imgHeight + 'px'
            $('img').animate({ 'left': distance }, 500)
            $('.dis>span').eq(currentIndex).addClass('bg').siblings().removeClass('bg')

            fun()
        })

        // 下一张
        $('.next').click(function () {
            clearInterval(show)
            currentIndex = currentIndex >= length - 1 ? 0 : ++currentIndex
            let distance = -currentIndex * imgHeight + 'px'
            $('img').animate({ 'left': distance }, 500)
            $('.dis>span').eq(currentIndex).addClass('bg').siblings().removeClass('bg')
            fun()
        })

    </script>
</body>

</html>